const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function checkStockAdjustments() {
  try {
    const adjustments = await prisma.stockAdjustment.findMany({
      include: {
        product: {
          select: {
            id: true,
            name: true
          }
        },
        warehouse: {
          select: {
            id: true,
            name: true
          }
        },
        operator: {
          select: {
            id: true,
            username: true
          }
        }
      },
      orderBy: {
        createdAt: 'desc'
      }
    });
    
    console.log('库存调整记录数:', adjustments.length);
    adjustments.forEach(adjustment => {
      console.log('----------');
      console.log('ID:', adjustment.id);
      console.log('产品:', adjustment.product.name);
      console.log('仓库:', adjustment.warehouse.name);
      console.log('操作员:', adjustment.operator.username);
      console.log('调整前数量:', adjustment.beforeQuantity);
      console.log('调整后数量:', adjustment.afterQuantity);
      console.log('调整数量:', adjustment.adjustmentQuantity);
      console.log('调整类型:', adjustment.adjustmentType);
      console.log('备注:', adjustment.remarks);
      console.log('创建时间:', adjustment.createdAt);
    });
  } catch (error) {
    console.error('查询库存调整记录失败:', error);
  } finally {
    await prisma.$disconnect();
  }
}

checkStockAdjustments(); 